<?php 
require_once 'config.php';
define('WOTHUB_ERR_CAL', 'Aucun &eacute;v&eacute;nement associ&eacute; au clan,' );
define('WOTHUB_ERR_CLAN', 'L\'identifiant du clan n\'a pas &eacute;t&eacute; sp&eacute;cifi&eacute;' );

if (isset($_GET['cid']) === true) {
    $clanId = $_GET['cid'] ;
    $cal = Model_Agenda::getShortEventListe($clanId);
    if ($cal !== false) {
        echo '<html><head>
                <link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:300|Roboto+Condensed:400,300">
                <style> body{background-color:#BBB}li{list-style-type:none} img{width:16px; margin-right:5px; vertical-align:text-top} a{text-decoration:none;} *{ color:#4D4D4D; font-family:"Roboto Condensed"; font-weight:100;font-size:10pt} 
                ul {margin:0px; padding:0px} ul ul{padding-left:10px; margin-bottom:10px}
                </style></head><body>';
        echo '<ul>';
        
        foreach ($cal as $dateEvent => $events) {
            $time = mktime(0, 0, 0, substr($dateEvent, 4, 2), substr($dateEvent, 6, 2), substr($dateEvent, 0 ,4));
            $dateF = strftime('%A %d %B %Y', $time);
            echo '<li>'.$dateF.'<ul>';
            foreach ($events as $event) {
                $url = $application['baseUri'].'Agenda/afficherDetail/'.$event['agenda_id'];
                $titre = $event['nom'];
                if ($event['titre'] !== null) {
                    $titre = $event['titre'];
                }
                echo '<li><img src="'.$event['image'].'"/><a href="'.$url.'" target="_blank">'.$titre.'</a></li>';
            }
            echo '</ul></li>';
        }
        echo '</ul></body></html>';
    }
    else {
        echo WOTHUB_ERR_CAL;
    }
}
else {
    echo WOTHUB_ERR_CLAN; 
}
